import json

from django.http.response import HttpResponse
from .runnerController import adHocRunner
from django.views import View


class runAdhoc(View):
    @staticmethod
    def post(request):
        # password = dict(vault_pass="123456")
        xx = ["192.168.56.102"]

        runAnsible = adHocRunner(inventory=xx, connection="smart",
                                 remote_user="root", remote_password="123456", remote_port="22")

        runAnsible.palyRun(hosts="192.168.56.102",
                           module="shell", args='touch /root/aa.txt')
        stdoutDict = json.loads(runAnsible.getResult())
        print(stdoutDict, type(stdoutDict))

        return HttpResponse("ok")
